package com.leetcode.doublePointer;

import java.util.Scanner;

/**
 * 双指针  leecode1147  段式回文
 */
public class Solution1147 {

    public int longestPalindrome(String text) {
        if (text == null || text.length() == 0) {
            return 0;
        }
        int start = 0;
        int end = text.length() - 1;
        // 游标指针
        int left = 0;
        int right = text.length() - 1;

        int result = 0;

        while (left < right) {
            if (text.substring(start, left + 1).equals(text.substring(right, end + 1))) {
                result += 2;
                // 更新
                start = left + 1;
                end = right - 1;
            }
            left++;
            right--;
        }

        if (left == right || (start != left && end != right)) {
            result++;
        }

        return result;
    }

    public static void main(String[] args) {
        Solution1147 solution1147 = new Solution1147();
        Scanner scanner = new Scanner(System.in);
        System.out.println(solution1147.longestPalindrome(scanner.next()));
    }
}
